﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once
#include "GbmpCommandBase.h"
#include "StructureColumnInput.h"
#include "UniIdentity.h"

namespace gcmp
{
    class ISnap;
    class IInstance;
    class IPropertyPanelEventArgs;

    class CmdDrawStructureColumnBase :public GbmpCommandBase
    {
    public:
        CmdDrawStructureColumnBase(const std::wstring &cmd);

    protected:
        virtual UniIdentity GetCategory() const = 0 ;
        virtual Int32 GetCategorySecondKey() const = 0;
        virtual std::wstring GetDefaultFamilyName() const = 0;
        virtual bool OnExecuteCommand() const;

    protected:
        bool GetFamilyNameAndInstanceTypeFromCommandParams(const CommandParameters& cmdParams, std::wstring &familyName, std::wstring &instanceType);
        bool GetFamilyNameAndInstanceType(std::wstring &familyName, std::wstring& instanceType);
        bool CreateDefaultFamilyDocument();
    };


    // CmdDrawStructureVerticalColumn
    class CmdDrawStructureVerticalColumn : public CmdDrawStructureColumnBase
    {
    public:
        CmdDrawStructureVerticalColumn();

#pragma region Command接口 
    public:
        virtual bool IsEnabled() const override;
        virtual bool IsVisible() const override;
        virtual OwnerPtr<gcmp::IAction> ExecuteCommand(const gcmp::CommandParameters& cmdParams) override;
#pragma endregion Command接口

#pragma region ColumnCommandBase接口
        virtual UniIdentity GetCategory() const override;
        virtual Int32 GetCategorySecondKey() const override;
        virtual std::wstring GetDefaultFamilyName() const override;
#pragma endregion ColumnCommandBase接口

    private:
        // 命令执行前清空选择集
        virtual bool ShouldClearSelectionBeforeExecution() const override { return true; }
    };


    // CmdDrawStructureSlantedColumn
    class CmdDrawStructureSlantedColumn : public CmdDrawStructureColumnBase
    {
    public:
        CmdDrawStructureSlantedColumn();

#pragma region Command接口
    public:
        virtual bool IsEnabled() const override;
        virtual bool IsVisible() const override;
        virtual OwnerPtr<gcmp::IAction> ExecuteCommand(const gcmp::CommandParameters& cmdParams) override;
#pragma endregion Command接口

#pragma region ColumnCommandBase接口
        virtual UniIdentity GetCategory() const override;
        virtual Int32 GetCategorySecondKey() const override;
        virtual std::wstring GetDefaultFamilyName() const override;
#pragma endregion ColumnCommandBase接口

    private:
        void OnActionInit(gcmp::IUiView* pCurrentView);
        gcmp::ElementId OnLineFinished(gcmp::IUiView* pCurrentView, const gcmp::Vector3d& startPt, const gcmp::Vector3d& endPt,
            const gcmp::ISnap* pStartSnap, const gcmp::ISnap* pEndSnap);
        gcmp::OwnerPtr<gcmp::IGraphicsNodeGroup> OnLineUpdate(gcmp::IUiView* pCurrentView, const gcmp::Vector3d& startPt,
            const gcmp::Vector3d& endPt);
        void OnEnterGettingStartPointState(gcmp::IUiView* pCurrentView);
        void OnEnterGettingEndPointState(gcmp::IUiView* pCurrentView);
        void OnActionDestroy();
        void OnPropertyPanelEvent(gcmp::IPropertyPanelEventArgs* pArgs);

        OwnerPtr<StructureColumnInput> GetInstanceInput();
        ElementId CreateInstance(const Vector3d& firsrPoint, const Vector3d& secondPoint, bool isVisible,
            bool canBeShared, ElementCreationOptions createOption = ElementCreationOptions::Normal);
        bool SetFamilyIdAndInstanceTypeId(ElementId familyId, ElementId instanceTypeId);

        // 命令执行前清空选择集
        virtual bool ShouldClearSelectionBeforeExecution() const override { return true; }

    private:
        ElementId m_familyId;
        ElementId m_instanceTypeId;
    };
}
